import flash.display.Sprite;
import flash.display.Shape;
import flash.display.InteractiveObject;
import flash.display.LineScaleMode;
import flash.events.Event;


import flash.geom.Rectangle;
import flash.events.MouseEvent;

/*
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0xFFCC00);
circle.graphics.drawCircle(200, 200, 200);
circle.scrollRect = new Rectangle(0, 0, 200, 200);
addChild(circle);

circle.addEventListener(MouseEvent.CLICK, clicked);

function clicked(event:MouseEvent):void {
    var rect:Rectangle = event.target.scrollRect;
    rect.y -= 5;
    event.target.scrollRect = rect;
}

*/


class Bounds extends Sprite
{

   var mBox:Sprite;
   var mRot:Float;
   
   public function new()
   {
      super();
      flash.Lib.current.addChild(this);
      name = "Main Sprite";


      mBox = new Sprite();
      addChild(mBox);

      var gfx1 = mBox.graphics;
      gfx1.lineStyle(20,0xff0000,1,false,flash.display.LineScaleMode.NORMAL,null,
                                         flash.display.JointStyle.MITER, 3.0);
      gfx1.moveTo(-50,-50);
      gfx1.lineTo(200,200);
      gfx1.lineTo(-50,200);
      gfx1.lineTo(-50,-50);
      mBox.x = 320;
      mBox.y = 240;
      mBox.name = "mBox";
      mBox.opaqueBackground = 0xa0a0c0;
      opaqueBackground = 0xe0e0e0;

      gfx1.lineStyle(1,0);
      gfx1.beginFill(0x00ff00);
      gfx1.drawCircle(0,0,20);

      //mBox.scrollRect = new Rectangle(-50,-50,200,200);

      mRot = -20.0;
      
      addEventListener(Event.ENTER_FRAME, OnEnterFrame);
      mBox.addEventListener(MouseEvent.CLICK, OnClick);

      var modes = [ LineScaleMode.NONE, LineScaleMode.NORMAL,
                   LineScaleMode.HORIZONTAL, LineScaleMode.VERTICAL, LineScaleMode.NORMAL ];
      for(i in 0...10)
      {
         var mod = i % 5;
         var obj = new Shape();
         var gfx = obj.graphics;
         gfx.lineStyle(mod==4 ? 0 : 4 ,0,1,false,modes[mod]);
         gfx.beginFill(0xff0000);
         gfx.drawCircle(0,0,8);
         //obj.cacheAsBitmap = true;
         obj.opaqueBackground = 0x707070;
         if (i>4)
            obj.rotation = 90;
         obj.x = 100 + mod*100;
         obj.y = i>4 ? 200 : 100;
         obj.scaleX = 4;
         obj.scaleY = 2;
         addChild(obj);
     }

     stage.scaleMode = flash.display.StageScaleMode.SHOW_ALL;
   }

   function OnEnterFrame(inEvent:Event)
   {
      mRot+= 0.1;
      mBox.rotation = mRot;
   }
   function OnClick(event:MouseEvent)
   {
       trace(event.target);
       //var rect:Rectangle = event.target.scrollRect;
       //trace(rect);
       //rect.y -= 5;
       //event.target.scrollRect = rect;
   }


   static public function main()
   {
      neash.Lib.Init("Bounds",640,480,false,true); 
      neash.Lib.SetBackgroundColour(0xffffff); 

      new Bounds();

      // neash addition ...
      neash.Lib.Run(); 
   }
}

